package pCloud.stream;

import java.util.Vector;

/*
 * The data stream class
 * It contains a name and a list of attributes
 */

public class Stream {
	
	public String name;
	public Vector<StreamAttribute> attributes;
	
	public Stream(String name) {
		this.name = name;
		this.attributes = new Vector<StreamAttribute>();
	}
	
	public Stream() {
		
		this.attributes = new Vector<StreamAttribute>();
	}
	
	public void addAttribute(StreamAttribute attr){
		
		this.attributes.add(attr);
	}
	
	public void print(){
		System.out.println("Stream Name : " + this.name);
		for (int i=0; i< this.attributes.size(); i++) {
			System.out.print("Stream Attribute : ");
			this.attributes.elementAt(i).print();
			System.out.println();
		}
	}
	
	public String createSSQL(){
		
		String ssql="";
		ssql="CREATE INPUT STREAM " + this.name + " ( " + Global.eol;
		
		if (this.attributes.size()>0){
			for (int i=0; i<this.attributes.size()-1;i++){
				ssql += this.attributes.elementAt(i).attributeName + " " + this.attributes.elementAt(i).attributeType + " , " + Global.eol;			
			}
			ssql += this.attributes.elementAt(this.attributes.size()-1).attributeName + " " + this.attributes.elementAt(this.attributes.size()-1).attributeType + " ); " + Global.eol;
		}	
		return ssql;		
	}
}

